import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2022-04-13
 * Time: 14:07
 */
public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack(){
        this.elem = new int[5];
    }

    public void push(int val){ //压栈
        if(this.usedSize == 0){
            this.elem = Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[this.usedSize] = val;
        this.usedSize++;
    }

    public void pop(){ //出栈
        if (isEmpty()){
            throw new RuntimeException("栈为空！");
        }
        int oldval = this.elem[usedSize-1];
        this.usedSize--;
        System.out.println(oldval);
    }

    public int peek(){ //查看栈顶元素
        if (isEmpty()){
            throw new RuntimeException("栈为空！");
        }
        return this.elem[usedSize-1];
    }

    public boolean isEmpty(){
        return this.usedSize == 0;
    }


}
